package cn.edu.jxau.test;

import java.util.Objects;
import java.util.Vector;

import cn.edu.jxau.util.LinkedQueue;
import cn.edu.jxau.util.Queue;

/**
 * @author Fudashi
 */
public class Main {

	public static void main(String[] args) {

		int[] arr = new int[] { 1, 1, 1, 0, 1 };
		System.out.println(min(arr));
	}

	private static int min(int[] arr) {

		Objects.requireNonNull(arr, "参数arr不能为null");
		if (arr.length == 0) {
			throw new IllegalArgumentException("空数组无最小值");
		}
		int low = 0;
		int high = arr.length - 1;
		int mid = low;
		while (arr[low] >= arr[high]) {
			if (high - low == 1) {
				mid = high;
				break;
			}
			mid = low + ((high - low) >> 1);
			if (arr[low] == arr[mid] && arr[mid] == arr[high]) {
				int minIndex = 0;
				for (int i = 1; i < arr.length; i++) {
					if (arr[minIndex] > arr[i]) {
						minIndex = i;
					}
				}
				return arr[minIndex];
			} else if (arr[low] <= arr[mid]) {
				low = mid;
			} else {
				high = mid;
			}
		}
		return arr[mid];
	}
}